﻿@using Huirui.Cavan.Domain.MainBoundedContext.SystemModule
@model Huirui.Cavan.Presentation.ViewModel.SystemModule.ICustomerViewModel
@{Layout = null;}
@using (Html.BeginForm(ActionConst.ADD, ControllerConst.CUSTOMER))
{
    <div class="tool_bar">
        <input id="customer_save" type="submit" value="save" style="display: none;" />
        <input id="cust_reset" type="reset" style="display: none" />
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'" onclick="javascript:$('#customer_save').click()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-undo'" id="customer_reset">重置</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" onclick="addTab('客户档案列表','center_tt','@Url.Action(ActionConst.LIST, ControllerConst.CUSTOMER)')">查询</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-collapse'" onclick="toggleHeard()">折叠/展开</a>
    </div>
    
    <table class="form_heard">
        <tr>
            <td class="c100">
                <label class="BlueRequired">编号:</label>
            </td>
            <td class="c160">
                @{
    var createTypeList = new List<SelectListItem>();
    createTypeList.Add(new SelectListItem() { Selected = true, Text = "自动生成", Value = "1" });
    createTypeList.Add(new SelectListItem() { Text = "手工输入", Value = "0" });
                }
                <table class="form_heard" style="border-collapse: collapse">
                    <tr>
                        <td class="c80" style="padding: 0">
                            @Html.DropDownList("customerid_type", createTypeList)
                        </td>
                        <td class="c80">
                            @Html.TextBoxFor(m => m.NoPrefixId, new { id = "cusstomer_NoPrefixId" })
                            @Html.TextBoxFor(m => m.Item.Id, new { id = "cusstomer_Id", style = "display:none;" })
                        </td>
                    </tr>
                </table>
            </td>
            <td class="c100">
                <label class="BlueRequired">客户性质:</label>
            </td>
            <td class="c160">
                @Html.DropDownListFor(m => m.Nature, typeof(SystemIdentifier.CustomerNature), new { id = "nature"})
            </td>
            <td class="c160"></td>
        </tr>
        <tr>
            <td class="c100">
                <label class="BlueRequired">名称:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.Name, new { id = "name" })
            </td>
            <td class="c100">
                <label>类别:</label>
            </td>
            <td class="c160">
                @Html.DropDownListFor(m => m.AgentType, typeof(SystemIdentifier.AgentType), new { id = "agenttype" })
            </td>
            <td class="c160"></td>
        </tr>
        <tr>
            <td class="c100">
                <label>业务员:</label>
            </td>
            <td class="c160">
                @Html.DropDownListFor(m => m.EmployeeRole, typeof(SystemIdentifier.Role), new { id = "employeerole" })
            </td>
            <td class="c100">
                <label>所属地区:</label>
            </td>
            <td colspan="2">
                @{ Html.RenderAction(ActionConst.SELECTAREA, ControllerConst.AREA, new { purpose = "ForCustomer", cityID = @Model.CityID, provinceID = @Model.ProvinceID }); }
                @Html.HiddenFor(m => m.Item.Area.Id, new { id = "areaForCustomer" })
            </td>
        </tr>
        <tr>
            <td class="c100">
                <label>发货地点:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.WareHouse.Address, new { id = "wareHouseAddressForCustomer" })
                @Html.TextBoxFor(m => m.Item.WareHouse.Id, new { id = "wareHouseCodeForCustomer", style = "display:none;" })
            </td>
            <td class="c100">
                <label>备注:</label>
            </td>
            <td colspan="2">
                @Html.TextBoxFor(m => m.Item.Remark, new { id = "remark" })
            </td>
        </tr>
    </table>
    <fieldset>
        <legend>联系方式</legend>
        <table class="form_heard">
            <tr>
                <td class="c100">
                    <label>联系人:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Contact, new { id = "contact" })
                </td>
                <td class="c100">
                    <label>电话号码:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Telephone, new { id = "telephone" })
                </td>
                <td class="c100">
                    <label>手机号码:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Mobile, new { id = "mobile" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>传真号码:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Fax, new { id = "fax" })
                </td>
                <td class="c100">
                    <label>Email:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Email, new { id = "email" })
                </td>
                <td class="c100">
                    <label>邮编:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.PostCode, new { id = "postcode" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>通讯地址(中文):</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.Address, new { id = "address" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>通讯地址(英文):</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.AddressEnglish, new { id = "addressenglish" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>送货地址:</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.DeliveryAddress, new { id = "deliveryaddress" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>送货地址1:</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.DeliveryAddress1, new { id = "deliveryaddress1" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>送货地址2:</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.DeliveryAddress2, new { id = "deliveryaddress2" })
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>会计属性</legend>
        <table class="form_heard">
            <tr>
                <td class="c100">
                    <label>付款方式:</label>
                </td>
                <td class="c160">
                    @Html.DropDownListFor(m => m.PayType, typeof(SystemIdentifier.PayType), new { id = "paytype"})
                </td>
                <td class="c100">
                    <label>折扣率:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.DiscountRate, new { id = "discountrate" })
                </td>
                <td class="c10">
                    @Html.Raw("%")
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>账期[天]:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.PayDay, new { id = "payday" })
                </td>
                <td class="c100">
                    <label>信用额度:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.CreditLimit, new { id = "creditlimit" })
                </td>
                <td class="c10"></td>
            </tr>
            <tr>
                <td class="c100">
                    <label>纳税识别号:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.TaxIdentificationNumber, new { id = "taxidentificationnumber" })
                </td>
                <td class="c100">
                    <label>开票类型:</label>
                </td>
                <td class="c160">
                    @Html.DropDownListFor(m => m.InvoiceType, typeof(SystemIdentifier.InvoiceType), new { id = "invoicetype" })
                </td>
                <td class="c10"></td>
            </tr>
            <tr>
                <td class="c100">
                    <label>开户银行:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Bank, new { id = "bank" })
                </td>
                <td class="c100">
                    <label>开户账号:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.BankAccount, new { id = "bankaccount" })
                </td>
                <td class="c10"></td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend class="left_right_bord_0">维护其它信息</legend>
        <div class="customer_div">
            <a>应收款初始余额:</a>
            <a>销售信息维护</a>
        </div>
    </fieldset>
}
@{ Html.RenderAction(ActionConst.SEARCH, ControllerConst.WAREHOUSE, new { purpose = "ForCustomer" }); }
<script type="text/javascript">
    $("#cusstomer_NoPrefixId").attr("disabled", true);
    $("select#customerid_type").bind("change", function () {
        if ($(this).val() == "1") {
            $("#cusstomer_NoPrefixId").attr("disabled", true);
        }
        else {
            $("#cusstomer_NoPrefixId").attr("disabled", false);
        }
    });
    $("#customer_reset").bind("click", function () {
        $('#cust_reset').click();
        if ($('select#customerid_type').val() == "1") {
            $("#cusstomer_NoPrefixId").attr("disabled", true);
        }
        else {
            $("#cusstomer_NoPrefixId").attr("disabled", false);
        }
    });
    $(function () {
        $("form[action^='/customer/add']").submit(function () {
            $("#areaForCustomer").val($("#cityForCustomer").val());
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (data) {
                    if (data.IsSuccess) {
                        alert(data.Messages[0]);
                    }
                },
                error: function () {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });

        $("#wareHouseAddressForCustomer").bind("click", function ()
        {
            InitSelectWareHouse('wareHousesForCustomer');
            openWindow("selectWareHouseWindowForCustomer");
        });

        $("#doSelectWareHouseForCustomer").bind("click", function ()
        {
            var currentRow = $('#wareHousesForCustomer').datagrid('getSelected');
            $("#wareHouseCodeForCustomer").val(currentRow.Id);
            $("#wareHouseAddressForCustomer").val(currentRow.Address);
            closeWindow("selectWareHouseWindowForCustomer");
        });

        $("#searchWareHouseForCustomer").submit(function ()
        {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result)
                {
                    if (result.total > 0)
                    {
                        $('#wareHousesForCustomer').datagrid({
                            data: result,
                            checkOnSelect: true,
                            selectOnCheck: true
                        });
                    }
                },
                error: function ()
                {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });


        $("#provinceForCustomer").bind("change", function () { getSelectItem($("#provinceForCustomer").val(), $("#cityForCustomer")) });
        //        $("#cityForCustomer").bind("change", function () { getAreaValue("areaForCustomer", $(this).val()) });
    });
</script>
